<?php
    if(isset($_GET["mode"])&&$_GET["mode"]=="install"){
        $dbname=$_GET["dbname"];
        $servername=$_GET["servername"];
        $username=$_GET["username"];
        $password=$_GET["password"];
        $con=mysqli_connect($_GET["servername"],$_GET["username"],$_GET["password"],$_GET["dbname"]);
        if (!$con){
            echo "数据库链接失败";
        }else{
            mysqli_query($con,"CREATE TABLE `".$dbname."`.`star_php_starbit_product` ( `id` VARCHAR(100) NOT NULL , `name` TEXT NOT NULL , `status` INT NOT NULL) ENGINE = InnoDB;");//部署蓝星云产品
            mysqli_query($con, "ALTER TABLE `star_php_starbit_product` ADD PRIMARY KEY(`id`);");
            mysqli_query($con,"CREATE TABLE `".$dbname."`.`star_php_website` ( `id` VARCHAR(100) NOT NULL , `name` TEXT NOT NULL , `status` INT NOT NULL) ENGINE = InnoDB;");//部署蓝星云产品
            mysqli_query($con, "ALTER TABLE `star_php_website` ADD PRIMARY KEY(`id`);");
            mysqli_query($con, "CREATE TABLE `$dbname`.`star_php_log` ( `ip` VARCHAR(50) NOT NULL , `time` INT NOT NULL , `times` INT NOT NULL , `black_times` INT NOT NULL , `black_time` INT NOT NULL , `between` INT NOT NULL) ENGINE = InnoDB;");
            mysqli_query($con, 'ALTER TABLE `star_php_log` ADD PRIMARY KEY(`ip`);');
            mysqli_query($con, "CREATE TABLE `$dbname`.`star_php_code` ( `id` VARCHAR(50) NOT NULL , `text` INT NOT NULL) ENGINE = InnoDB;");
            mysqli_query($con, 'ALTER TABLE `star_php_code` ADD PRIMARY KEY(`id`);');
            mysqli_query($con, "CREATE TABLE `$dbname`.`star_php_search_msg` ( `id` VARCHAR(150) NOT NULL , `time` INT NOT NULNUL , `weight` INT NOT NULNUL, `title` TEXT NOT NULNUL, `html` TEXT NOT NULNUL, `url` TEXT NOT NULNUL) ENGINE = InnoDB;");
            mysqli_query($con, 'ALTER TABLE `star_php_search_msg` ADD PRIMARY KEY(`id`);');
            mysqli_query($con, "INSERT INTO `star_php_website` (`id`, `name`, `status`) VALUES ('index', '官网', '1');");
            mysqli_query($con, "INSERT INTO `star_php_website` (`id`, `name`, `status`) VALUES ('admin_cms', 'cms管理页面', '1');");
            //mysqli_query($con,"CREATE TABLE `".$dbname."`.`star_php_token` ( `id` VARCHAR(100) NOT NULL , `time` INT NOT NULL , `status` INT NOT NULL) ENGINE = InnoDB;");//面板临时链接
            //mysqli_query($con, "ALTER TABLE `star_php_token` ADD PRIMARY KEY(`id`);");
            echo "<script>window.location.replace(\"../admin/index.php?pa=1\")</script>";       
        }
        $myfile = fopen("../config.php", "w") or die("Unable to open file!");
        fwrite($myfile,'<?php $servername="'.$servername.'";$username="'.$username.'";$dbname="'.$dbname.'";$password="'.$password.'";$smtpurl="'.$_GET["smtpurl"].'";$smtpemail="'.$_GET["smtpemail"].'";$smtpkey="'.$_GET["smtppassword"].'";$smtpport=465;$tellemail="'.$_GET["tellemail"].'"; $token_pass="'.$_GET["token_pass"].'"?>');
        fclose($myfile);
    }else{
        require("./html.php");
    }
?>